home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / joe014.zip / JOE014.TAZ / JOE014.tar / joe.h < prev    next >
C/C++ Source or Header  |  1992-01-23  |  18KB  |  534 lines

  1. /* JOE header file
  2.    Copyright (C) 1991 Joseph H. Allen
  3.  
  4. This file is part of JOE (Joe's Own Editor)
  5.  
  6. JOE is free software; you can redistribute it and/or modify it under the terms
  7. of the GNU General Public License as published by the Free Software
  8. Foundation; either version 1, or (at your option) any later version.  
  9.  
  10. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  13.  
  14. You should have received a copy of the GNU General Public License along with
  15. JOE; see the file COPYING.  If not, write to the Free Software Foundation, 675
  16. Mass Ave, Cambridge, MA 02139, USA.  */ 
  17.  
  18. /* File characteristics */
  19.  
  20. #define NL '\n'            /* End of line character */
  21. #define TAB '\t'        /* Tab character */
  22. #define TABWIDTH 8        /* Tab width */
  23. #define NOHIGHBIT        /* Comment this out to send characters with
  24.                    high bit set to terminal as is.  See
  25.                    the function 'showas'. */
  26.  
  27. /* Types used in the file buffer */
  28.  
  29. typedef unsigned char * TXTPTR;    /* Pointer to text in the buffer */
  30. typedef unsigned TXTSIZ;    /* Integer to hold size of file */
  31. #define TXTFREE(a) free(a)    /* Free a buffer */
  32. #define TXTMALLOC(a) malloc(a)    /* Allocate a buffer */
  33. #define TXTREALLOC(a,b) realloc((a),(b))    /* Reallocate a buffer */
  34.  
  35. /* File names and characteristics */
  36.  
  37. #define PATHSIZE 256        /* Maximum path length */
  38. #define KEYMAP ".joerc"        /* Keymap file */
  39. /* #define KEYDEF "/usr/bin/.joerc"    Default keymap file */
  40. #define ABORT "DEADJOE"        /* Aborted file */
  41.  
  42. /* The current file buffer */
  43. /* When you change windows, these variables get stored in the 'struct buffer'
  44.    associated with the old window and are load with the values in the
  45.    'struct buffer' for the new window */
  46.  
  47. extern TXTSIZ bufsiz;        /* Size of malloc block buffer is in */
  48. extern TXTPTR point;        /* The point (cursor) */
  49. extern TXTPTR buffer;        /* The buffer */
  50. extern TXTPTR filend;        /* First char not in buffer */
  51. extern TXTPTR hole;        /* Address of hole */
  52. extern TXTPTR ehole;        /* First char not in hole */
  53. extern int changed;        /* Set if buffer changed */
  54. extern int backup;        /* Set if backup file has been made */
  55. extern unsigned char gfnam[PATHSIZE];
  56.                 /* Current edit file name.  "" for unnamed */
  57.  
  58. #define HOLESIZE 1024        /* Amount file buffer grows by */
  59.  
  60. /*******************************************************/
  61. /* Basic file buffer manipulation functions and macros */
  62. /*******************************************************/
  63.  
  64. int fminsu();        /* fminsu(size) Adjust pointers by amnt inserted */
  65. int fmdelu();        /* fmdelu(size) Adjust pointers by amount deleted */ 
  66. /* The pointers the above two functions currently update include:
  67.     The pointer to start of each window which references the current
  68.     buffer.
  69.  
  70.     The pointer to cursor in each window which reference the current
  71.     buffer but not the one for the current window.
  72.  
  73.     The begin & end pointers to the marked block if they are in the
  74.     current buffer.
  75. */
  76.  
  77. /* Return size of hole */
  78.  
  79. #define fmholesize() (ehole-hole)
  80.  
  81. /* Read character at the point */
  82.  
  83. #define fmrc() (point==hole?*(point=ehole):*point)
  84.  
  85. /* Overtype character at the point */
  86.  
  87. #define fmwc(c) (((point==hole)?point=ehole:0),((point==filend)?(fmexpand(1),\
  88. filend++):0),*point=(c),changed=1)
  89.  
  90. /* Read character at point and advance point */
  91.  
  92. #define fmgetc() ((point==hole)?(point=ehole+1,*ehole):*(point++))
  93.  
  94. /* Overtype character at point and advance point */
  95.  
  96. #define fmputc(c) (((point==hole)?point=ehole:0),((point==filend)?(fmexpand(1),\
  97. filend++):0),*(point++)=(c),changed=1)
  98.  
  99. /* Insert character at point */
  100.  
  101. #define fminsc(c) ( fminsu(1), \
  102. (point!=hole?fmhole():0), (hole==ehole?fmbig(1):0),\
  103. *(hole++)=(c), changed=1)
  104.  
  105. /* Return the byte offset from the beginning of the buffer to the point */
  106.  
  107. #define fmnote() ((point>=ehole)?(point-buffer)-(ehole-hole):point-buffer)
  108.  
  109. /* Return the size of the file in the buffer */
  110.  
  111. #define fmsize() ((filend-buffer)-(ehole-hole))
  112.  
  113. /* Return true if the point is at the end of the file */
  114.  
  115. #define fmeof() ((point==hole)?(ehole==filend):(point==filend))
  116.  
  117. /* Position the point to a byte offset from the beginning of the file */
  118.  
  119. #define fmpoint(x) (point=buffer+(x), (point>hole)?(point+=ehole-hole):0)
  120.  
  121. /* Retreat the point and then read the character that's there */
  122.  
  123. #define fmrgetc() (point==ehole?*(point=hole-1):*(--point))
  124.  
  125. /* Position the point to the next NL or the end of the file.  If the point
  126.    is already at a NL, it is set to the next NL. Return 0 if not found, 1
  127.    if found */
  128.  
  129. #define fmnnl() (fmeof()?0:(fmgetc(),fmfnl()))
  130.  
  131. /* Set the point to the beginning of the file or the previous NL.  If the
  132.    point is already at a NL, it is set to the one before it.  Return 0 if
  133.    not found, 0 if found */
  134.  
  135. #define fmnrnl() (fmnote()?(fmrgetc(),fmrnl()):0)
  136.  
  137. int fmopen();            /* fmopen() Initialize current edit buffer */
  138. int fmexpand();            /* fmexpand(amount) Make buffer bigger */
  139. int fmhole();            /* fmhole() Move hole to point */
  140. int fmbig();            /* fmbig(size) Make hole at least size */
  141. int fmfnl();            /* Find first NL.  Returns 0 if not found */
  142.                 /* If at an NL already, point is not moved */
  143. int fmrnl();            /* Find NL in reverse.  Rtns 0 if not found */
  144.                 /* If at an NL already, point is not moved */
  145. int fminss();            /* fminss(blk,size) Insert a block at point */
  146. int fmcmp();            /* fmcmp(blk,size) return 0 if matching */
  147. int tupp();            /* tupp(c) Convert char to uppercase */
  148. int fmicmp();            /* Same as fmcmp but ignore case */
  149. int fmsave();            /* fmsave(FILE,size) Save at point in file */
  150. int fminsfil();            /* fminsfil(FILE) Insert file at point */
  151.  
  152. /******************/
  153. /* Terminal stuff */
  154. /******************/
  155.  
  156. /* Terminal characteristics (terminal must be vt100ish) */
  157.  
  158. extern int width;        /* Screen width */
  159. extern int height;        /* Screen height */
  160. extern int scroll;        /* Set if terminal has scrolling regions */
  161.  
  162. /* Terminal state */
  163.  
  164. extern int smode;        /* Current character attributes */
  165. extern int tops;        /* Scroll region top (-1 for unknown) */
  166. extern int bots;        /* Scroll region bottem */
  167. extern int oxpos;        /* Cursor position */
  168. extern int oypos;
  169. extern int *scrn;        /* Screen buffer
  170.                     -1 means unknown character
  171.                     0 - 255 means known character
  172.                 */
  173.  
  174. extern unsigned char *omsg;    /* Opening message */
  175. int dopen();                        /* Open display (clear it, allocate scrn,
  176.                    etc.) */
  177. int dclose();                       /* dclose(s) Show final message and close
  178.                    display */
  179.  
  180. int cposs();            /* cpos(row,col) Set cursor position */
  181. int cpos();                /* cpos(row,col) Set cursor position and
  182.                    update ox/oypos */
  183. int setregn();            /* setregn(top,bot) Set scroll region */
  184.  
  185. int attrib();            /* attrib(mask) Set attributes */
  186. #define INVERSE 256
  187. #define BLINK 512
  188. #define UNDERLINE 1024
  189. #define BOLD 2048
  190.  
  191. /*****************/
  192. /* Screen update */
  193. /*****************/
  194.  
  195. /* Flags which high-level edit functions set to control the screen
  196.    update.  All three are initialized to 0 before an edit function
  197.    is executed */
  198.  
  199. extern int uuu;            /* Set is no screen update needed */
  200. extern int cntr;        /* Set to center cursor to middle of
  201.                    screen if the screen will scroll
  202.                    (for search/replace) */
  203. extern int newy;        /* Set if row changed */
  204. extern int updall;        /* Set to update all windows, not just
  205.                    the ones with same buffer */
  206.  
  207. /* Flags which indicate the current progress of a screen update (I.E., so
  208.    we can continue if user interrupts screen update) */
  209.  
  210. extern int upd;            /* Set if a screen update should be done */
  211. extern int hupd;        /* Set if a help update should be done */
  212.  
  213. extern int helpon;        /* Set if help screen is on */
  214. extern int wind;        /* Number of help lines */
  215.  
  216. extern int xpos;        /* Requested x & y positions (as determined */
  217. extern int ypos;        /* by scroll calculator: dupdate1 */
  218.  
  219. extern TXTSIZ saddr;        /* Byte offset to first char of first screen
  220.                    line (of current window) */
  221. extern TXTSIZ xoffset;        /* Cols current window is scrolled to right */
  222. extern TXTSIZ extend;        /* Column number if past end of line or in
  223.                    tab stop */
  224.  
  225. /* Functions for doing screen update */
  226.  
  227. int clreolchk();        /* clreolchk(lin,col) Clear to end of line if needed */
  228. int udline();        /* udline(lin) Update a single line.  Return true
  229.                EOF reached */
  230. int udscrn();        /* Update screen (returns true if it finished) */
  231. int dupdate1();        /* dupdate1(flg) Recalculate cursor, scroll & update
  232.                screen (sets cursor position if flg is set) */
  233. int dupdatehelp();        /* Update help */
  234. int dupdate();        /* Update help and screen */
  235. int invalidate();        /* invalidate(lin) Invalidate a line so it gets upd. */
  236.  
  237. /****************/
  238. /* Window Stuff */
  239. /****************/
  240.  
  241. /* Each file that's edited has a 'struct buffer' associated with it.
  242.    This stores the buffer variables when the buffer is not the current
  243.    buffer (I.E., when the cursor is in a window for another file).
  244. */
  245.  
  246. struct buffer
  247.  {
  248.  int count;        /* Reference count (No. windows into this buffer) */
  249.  TXTSIZ bufsiz;        /* Size of malloc block buffer is in */
  250.  TXTPTR buf;        /* The buffer */
  251.  TXTPTR filend;        /* First char not in buffer */
  252.  TXTPTR hole;        /* Address of hole */
  253.  TXTPTR ehole;        /* First char not in hole */
  254.  int changed;        /* Set if buffer changed */
  255.  int backup;        /* Set if backup file has been made */
  256.  unsigned char gfnam[PATHSIZE];    /* Current edit file name.  "" for unnamed */
  257.  struct undorec *undorecs;
  258.  struct undorec *redorecs;
  259.  int nundorecs;
  260.  };
  261.  
  262. /* Each window has a 'struct window' associated with it */
  263.  
  264. struct window
  265.  {
  266.  struct window *next;    /* Doubly linked list of windows */
  267.  struct window *prev;
  268.  
  269.  struct buffer *buffer;    /* The buffer this window looks at */
  270.  
  271.  /* Screen variables for each window */
  272.  
  273.  TXTSIZ saddr;        /* Byte offset to first character of first line in
  274.                 window */
  275.  TXTSIZ xoffset;    /* No. columns the screen is scrolled to the right */
  276.  
  277.  /* Window size */
  278.  
  279.  int wind;         /* Starting screen line */
  280.             /* wind is not the same as 'wind' the number of
  281.                help lines */
  282.  int height;       /* Height of window */
  283.  int hheight;      /* Height before help turned on */
  284.  
  285.  /* Edit modes */
  286.  
  287.  int pic;
  288.  int autoind;
  289.  int overwrite;
  290.  int wrap;
  291.  int tabmagic;
  292.  TXTSIZ rmargin;
  293.  
  294.  /* Cursor position */
  295.  
  296.  TXTSIZ extend;        /* Column number if cursor is past end of line or
  297.                 if it's in a tab stop */
  298.  TXTSIZ cursor;        /* Byte offset (in buffer) to the cursor */
  299.  
  300.  };
  301.  
  302. extern struct window *wfirst;    /* Doubly linked list of windows */
  303. extern struct window *wlast;
  304.  
  305. extern struct window *curwin;    /* Current window */
  306. extern struct buffer *curbuf;    /* Current buffer */
  307. extern struct window *topwin;    /* First window on the screen */
  308.  
  309. /* Keyboard and command table handler */
  310.  
  311. typedef struct key KEY;
  312. struct key
  313.  {
  314.  int k;                 /* Key value */
  315.  int *n;                /* Command number or submap address */
  316.  };
  317.  
  318. typedef struct kmap KMAP;
  319. struct kmap
  320.  {
  321.  int len;          /* Number of KEY entries */
  322.  int size;         /* Size of malloc block */
  323.  KEY *keys;             /* KEYs.  Sorted. */
  324.  };
  325.  
  326. /* Masks & bits for k */
  327.  
  328. #define KEYMASK 0x7fff
  329. #define KEYSUB 0x8000    /* Set for submap */
  330.  
  331. /* A command entry */
  332.  
  333. typedef struct cmd CMD;
  334. struct cmd
  335.  {
  336.  char *name;
  337.  int flag;
  338.  int (*func)();
  339.  };
  340.  
  341. /* A context (group of related commands) */
  342.  
  343. typedef struct context CONTEXT;
  344. struct context
  345.  {
  346.  CONTEXT *next;        /* List of all contexts */
  347.  char *name;        /* Name of this context */
  348.  KMAP *kmap;        /* Top level keymap for this context */
  349.  int size;        /* Number of entries in this context */
  350.  CMD *cmd;        /* The entries themselves (sorted) */
  351.  };
  352.  
  353. int dokey();        /* dokey(c) Execute next key */
  354. extern int quoteflg;    /* Set if next key is quoted */
  355. extern int quote8th;    /* Set if next key is quoted */
  356.  
  357. /* dokey() Return values */
  358.  
  359. #define Kaccept -1    /* Key accepted but not executed */
  360. #define Kbad -2        /* Bad key */
  361. /* dokey() used to return a function number; now it executes the function
  362.    itself so the return values are meaningless */
  363.  
  364. /* Messages and queries */
  365.  
  366. /* These are all hacks because they return/check for exact key values
  367.    and don't know about the key table.  Someday a key 'context' should
  368.    be added for these
  369. */
  370.  
  371. int getl();        /* getl(prompt,line) Get a line of input */
  372.             /* Returns: -1 if user hits ^L
  373.                      1 if user hits \n or \r
  374.                      0 if user hits ^C
  375.                 (yes this is a stupid hack)
  376.             */
  377.  
  378. int msg();            /* msg(s) Show a message until user hits a key */
  379.  
  380. int askyn();        /* askyn(s) Yes/No question 
  381.             Returns: 'Y', 'N' or -1 for ^C */
  382.  
  383. int query();        /* query(s) Show message, wait for user to hit a key,
  384.                then return key. */
  385.  
  386. int nquery();        /* nquery(s) Same as query but leave cursor on
  387.                edit screen */
  388. int imsg();                 /* imsg() Show opening message */
  389.  
  390. /*******************************************/
  391. /* High-level edit functions and variables */
  392. /*******************************************/
  393.  
  394. /* Edit modes */
  395.  
  396. extern int pic;            /* Set for picture mode */
  397. extern int autoind;        /* Set for autoindent */
  398. extern int overwrite;        /* Set for overwrite */
  399. extern int wrap;        /* Set for autowrap */
  400. extern int tabmagic;        /* Set for magical tabs */
  401. extern TXTSIZ rmargin;        /* Current right margin */
  402.  
  403. /****************************/
  404. /* Search and replace stuff */
  405. /****************************/
  406.  
  407. /* Search & replace options */
  408.  
  409. #define s_ignore 1        /* Ignore case */
  410. #define s_backwards 2        /* Search backwards */
  411. #define s_replace 4        /* Replace */
  412. #define s_regex 8        /* Regular expression search */
  413.  
  414. extern int options;        /* Search options */
  415. extern unsigned char sstring[PATHSIZE];    /* Search string */
  416. extern unsigned char rstring[PATHSIZE];    /* Replace string */
  417. extern int len;            /* Length of search string */
  418.  
  419. /**********/
  420. /* Blocks */
  421. /**********/
  422.  
  423. extern TXTSIZ markb;        /* Begining of block */
  424. extern TXTSIZ marke;        /* End of block */
  425. extern struct buffer *markbuf;    /* Buffer block is in or 0 for no block */
  426.  
  427. /**************************************/
  428. /* High level edit function utilities */
  429. /**************************************/
  430.  
  431. extern int leave;        /* Edit function sets this to leave the editor
  432.                    after the function returns */
  433.  
  434. int dnarw();            /* Move cursor to next line */
  435.                 /* Column number is preserved */
  436. TXTSIZ calcs();            /* Calculate number of whitespace columns
  437.                    at beginning of line.  Cursor is left
  438.                    at first non-whitespace character */
  439. int saveit1();            /* saveit1(s) Save buffer in file & clear
  440.                    changed */
  441. int itype();
  442. int ltarw();            /* Move cursor left (goes to end of previous
  443.                    line if at beginning of line) */
  444. int uparw();            /* Move cursor up (preserves column) */
  445. int rtarw();                        /* Move cursor right (goes to beginning of
  446.                    next line if at end of line) */
  447.  
  448. /* Return current column number of cursor */
  449.  
  450. #define getcol() (extend?extend:getrcol())
  451.  
  452. TXTSIZ getrcol();        /* Get column number of point */
  453. int gocol();            /* gocol(col) Set cursor (point/extend) to
  454.                    column number */
  455. int unfill();            /* Remove trailing spaces from line */
  456. int fillup();                       /* Fill to extend position (use this only
  457.                    if extend if past end of line, not for
  458.                    if extend is in tab stop) */
  459.  
  460. int search();            /* Execute a search.  Returns 1 if found,
  461.                    0 if not */
  462.  
  463. /* Window functions */
  464.  
  465. int ldwin();            /* ldwin(window) load window */
  466. int stwin();            /* stwin(window) save window */
  467. int ldbuf();            /* ldbuf(buf) load buf if it's not already */
  468. int ldbuf1();            /* ldbuf1(buf) load buf always */
  469. int stbuf();            /* stbuf(buf) store buffer */
  470. int wfit();            /* make sure the current window is on screen */
  471.  
  472. /* High Level (user) edit functions */
  473.  
  474. int wnext();            /* goto next window */
  475. int wprev();            /* goto previous window */
  476. int wexplode();            /* show 1 or all windows */
  477. int wgrow();            /* make window bigger */
  478. int wshrink();            /* make window smaller */
  479. int wedit();            /* edit a new file */
  480. int wsplit();            /* Split window into 2 */
  481.  
  482. int rewrite();            /* Rewrite screen */
  483. int thelp();            /* Toggle help screen */
  484. int bof();            /* Goto beginning of file */
  485. int eof();            /* Goto end of file */
  486. int bol();            /* Goto beginning of line */
  487. int eol();                /* Goto end of line */
  488. int urtarw();            /* Move cursor right (scroll if need to) */
  489. int ultarw();
  490. int uuparw();
  491. int udnarw();
  492. int delch();            /* Delete character */
  493. int type();                /* type(c) type a character */
  494. int inss();                /* insert a space */
  495. int backs();            /* backspace */
  496. int eexit();            /* Exit & abort */
  497. int pgup();                /* 1/2 Page up */
  498. int pgdn();                /* 1/2 Page down */
  499. int deleol();            /* Erase end of line */
  500. int dellin();            /* Erase entire line */
  501. int exsave();            /* Save and exit */
  502. int saveit();            /* Save current file */
  503. int findline();            /* Goto line No. */
  504. int findfirst();            /* Find some text */
  505. int findnext();            /* Find next occurance */
  506. int setbeg();            /* Set beginning of block */
  507. int setend();            /* Set end of block */
  508. int writeblk();            /* Write block to file */
  509. int moveblk();            /* Move block to point */
  510. int cpyblk();            /* Copy block to point */
  511. int delblk();            /* Delete block */
  512. int insfil();            /* Insert a file */
  513. int push();                /* Execute a shell */
  514. int mode();                /* Change edit mode */
  515. int ctrlin();            /* Center current line */
  516. int reformat();            /* Reformat current paragraph */
  517. int killword();            /* Delete word */
  518. int backword();            /* Delete word to the left */
  519. int wrdl();                /* goto previous word */
  520. int wrdr();                /* goto next word */
  521. int macrob();
  522. int macroe();
  523. int macrodo();
  524. int edit();                /* Main edit loop */
  525. int waite();
  526. int macroadd();
  527. extern FILE *handle;        /* File handle used for many various things */
  528. extern TXTSIZ added;        /* Number of chars autoindent added
  529.                 (obsolete?) */
  530.  
  531. /* Portable strdup() */
  532.  
  533. #define strdupp(x) ((unsigned char *)strcpy((unsigned char *)malloc(strlen(x)+1),(x)))
  534.